<?php
 $q=$_GET["q"];
$hint="";
if(strlen($q)>0&&$q!="0")
{
include_once ("Login/databaseconnection.php");
$arr="";
$getinp_type=mysql_query("SELECT * FROM school WHERE School_Id LIKE'".$q."%'");
if($q[0]=="0"||$q[0]=="1"||$q[0]=="2"||$q[0]=="3"||$q[0]=="4"||$q[0]=="5"||$q[0]=="6"||$q[0]=="7"||$q[0]=="8"||$q[0]=="9")
{
if(mysql_num_rows($getinp_type)>0)
{
$attr='School_Id';
$getque=mysql_query("SELECT * FROM school");
while ($row= mysql_fetch_array($getque))
{
$Name=$row['School_Id'];
$value=substr($Name,0,strlen($q));
if(strcasecmp($value,$q)==0){
if($arr=="")
{
$arr=$Name;
}
else
{
$arr=$arr."_".$Name;
}
}
}
$getque=mysql_query("SELECT * FROM school");
while ($row= mysql_fetch_array($getque))
{
$Name=$row['Name'].','.$row['Address'];
$value=substr($Name,0,strlen($q));
if(strcasecmp($value,$q)==0){
if($arr=="")
{
$arr=$Name;
}
else
{
$arr=$arr."_".$Name;
}
}
}
}
else
{
$attr='Census_Number';
$getque=mysql_query("SELECT * FROM school");
while ($row= mysql_fetch_array($getque))
{
$Name=$row['Census_Number'];
$value=substr($Name,0,strlen($q));
if(strcasecmp($value,$q)==0){
if($arr=="")
{
$arr=$Name;
}
else
{
$arr=$arr."_".$Name;
}
}
}
}
}
else 
{
$attr='Name';
$getque=mysql_query("SELECT * FROM school");
while ($row= mysql_fetch_array($getque))
{
$Name=$row['Name'].','.$row['Address'];
$value=substr($Name,0,strlen($q));
if(strcasecmp($value,$q)==0){
if($arr=="")
{
$arr=$Name;
}
else
{
$arr=$arr."_".$Name;
}
}
}
}
  $array= explode("_",$arr);
 $hint=$hint."<input type='hidden' value='$attr' name='attribute' id='attribute'/>";
  $hint=$hint."<div style='height:35px; overflow-Y:scroll; '>";
for ($i = 0; $i <count($array); $i++) 
{
 $temp =$array[$i];
  if($temp!="")
  {
  $hint=$hint.'<li onClick="fill(\''.$temp.'\');">'.$temp.'</li>';
  }
  $j = $i;
  for ($k = 0; $k <count($array); $k++) 
  {
    if ($k != $j) {
      if ($temp == $array[$k]) 
	  {
        $array[$k]="";
      }
    }
  }
}
  $hint=$hint.'<div>';
}
if($hint=="<input type='hidden' value='$attr' name='attribute' id='attribute'/><div style='height:35px; overflow-Y:scroll; '><div>"||$hint=="")
{
$response="No suggestions";
}
else
{
$response=$hint;
}
echo $response;
?>